﻿// DATENOW_DIA.cpp: 实现文件
//

#include "stdafx.h"
#include "MFCApplication4.h"
#include "DATENOW_DIA.h"
#include "afxdialogex.h"
#include<vector>

extern string tmDateString(tmDate tmDatep);

// DATENOW_DIA 对话框

IMPLEMENT_DYNAMIC(DATENOW_DIA, CDialogEx)

DATENOW_DIA::DATENOW_DIA(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DATE, pParent)
{

}

DATENOW_DIA::~DATENOW_DIA()
{
}

void DATENOW_DIA::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT2, datenow);
	std::string getsNOW;
	getsNOW = tmDateString(SystemALL.nDate);
	CString bc(getsNOW.c_str());
	datenow.SetWindowTextW(bc);
	datenow.UpdateData(true);
}


BEGIN_MESSAGE_MAP(DATENOW_DIA, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON2, &DATENOW_DIA::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON5, &DATENOW_DIA::OnBnClickedButton5)
	ON_BN_CLICKED(IDC_BUTTON4, &DATENOW_DIA::OnBnClickedButton4)
END_MESSAGE_MAP()


// DATENOW_DIA 消息处理程序


void DATENOW_DIA::OnBnClickedButton2()
{
	int check = 0;
	string dates;
	CString datec;
	GetDlgItemText(IDC_EDIT1, datec);
	dates = CT2A(datec.GetString());
	// TODO: 在此添加控件通知处理程序代码
	vector<string> tmp;
	tmp.push_back("99");
	tmp.push_back(dates);
	for (vector<Controller>::iterator it = SystemALL.Center.begin(); it != SystemALL.Center.end(); it++)
	{
		if (it->getUsername() == SystemALL.usernow)
		{
			try {
				SystemALL.nDate = it->getCommand(tmp, SystemALL.nDate);
			}
			catch (runtime_error &e)
			{
				string tmp = e.what();
				tmp += "\r\n";
				SystemALL.WriteIntoEditer(tmp);
				check = 1;
			}
		}
	}
	if (check == 0)
	{
		std::string getsNOW;
		getsNOW = tmDateString(SystemALL.nDate);
		CString bc(getsNOW.c_str());
		datenow.SetWindowTextW(bc);
	}
}


void DATENOW_DIA::OnBnClickedButton5()
{
	// TODO: 在此添加控件通知处理程序代码
	int check = 0;
	vector<string> tmp;
	tmp.push_back("110");
	for (vector<Controller>::iterator it = SystemALL.Center.begin(); it != SystemALL.Center.end(); it++)
	{
		if (it->getUsername() == SystemALL.usernow)
		{
			try {
				SystemALL.nDate = it->getCommand(tmp, SystemALL.nDate);
			}
			catch (runtime_error &e)
			{
				string tmp = e.what();
				tmp += "\r\n";
				SystemALL.WriteIntoEditer(tmp);
				check = 1;
			}
		}
	}
	if (check == 0)
	{
		std::string getsNOW;
		getsNOW = tmDateString(SystemALL.nDate);
		CString bc(getsNOW.c_str());
		datenow.SetWindowTextW(bc);
	}
}


void DATENOW_DIA::OnBnClickedButton4()
{
	EndDialog(0);
	// TODO: 在此添加控件通知处理程序代码
}
